home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / mailstats / mailstats.c next >
Encoding:
C/C++ Source or Header  |  1991-06-26  |  2.6 KB  |  89 lines

  1. /*
  2.  * Copyright (c) 1983 Eric P. Allman
  3.  * Copyright (c) 1988 Regents of the University of California.
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms are permitted provided
  7.  * that: (1) source distributions retain this entire copyright notice and
  8.  * comment, and (2) distributions including binaries display the following
  9.  * acknowledgement:  ``This product includes software developed by the
  10.  * University of California, Berkeley and its contributors'' in the
  11.  * documentation or other materials provided with the distribution and in
  12.  * all advertising materials mentioning features or use of this software.
  13.  * Neither the name of the University nor the names of its contributors may
  14.  * be used to endorse or promote products derived from this software without
  15.  * specific prior written permission.
  16.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  17.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  18.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19.  *
  20.  */
  21.  
  22. #ifndef lint
  23. char copyright[] =
  24. "@(#) Copyright (c) 1988 Regents of the University of California.\n\
  25.  All rights reserved.\n";
  26. #endif /* not lint */
  27.  
  28. #ifndef lint
  29. static char sccsid[] = "@(#)mailstats.c    5.7 (Berkeley) 6/1/90";
  30. static char  rcsid[] = "@(#)$Id: mailstats.c,v 5.7.0.1 1991/06/26 15:50:30 paul Exp $";
  31. #ifdef    __GNUC__
  32. static    char    compiled[] = "@(#)compiled by gcc version "__VERSION__;
  33. #endif
  34. #endif /* not lint */
  35.  
  36. #include <sys/file.h>
  37. #include <sendmail.h>
  38. #include <mailstats.h>
  39. #include "pathnames.h"
  40.  
  41. int
  42. main(argc, argv)
  43.     int argc;
  44.     char **argv;
  45. {
  46.     extern char *optarg;
  47.     extern int optind;
  48.     struct statistics stat;
  49.     register int i;
  50.     int ch, fd;
  51.     char *sfile, *ctime();
  52.     int getopt();
  53.     void perror();
  54.  
  55.     sfile = _PATH_MAILSTATS;
  56.     while ((ch = getopt(argc, argv, "f:")) != EOF)
  57.         switch((char)ch) {
  58.         case 'f':
  59.             sfile = optarg;
  60.             break;
  61.         case '?':
  62.         default:
  63.             fputs("usage: mailstats [-f file]\n", stderr);
  64.             exit(EX_USAGE);
  65.         }
  66.     argc -= optind;
  67.     argv += optind;
  68.  
  69.     if ((fd = open(sfile, O_RDONLY)) < 0) {
  70.         fputs("mailstats: ", stderr);
  71.         perror(sfile);
  72.         exit(EX_NOINPUT);
  73.     }
  74.     if (read(fd, (char *)&stat, sizeof(stat)) != sizeof(stat) ||
  75.         stat.stat_size != sizeof(stat)) {
  76.         fputs("mailstats: file size changed.\n", stderr);
  77.         exit(EX_OSERR);
  78.     }
  79.  
  80.     printf("Statistics from %s", ctime(&stat.stat_itime));
  81.     printf(" M msgsfr bytes_from  msgsto   bytes_to\n");
  82.     for (i = 0; i < MAXMAILERS; i++)
  83.         if (stat.stat_nf[i] || stat.stat_nt[i])
  84.             printf("%2d %6lu %10lu  %6lu %10lu\n", i,
  85.                 stat.stat_nf[i], stat.stat_bf[i],
  86.                 stat.stat_nt[i], stat.stat_bt[i]);
  87.     return(0);
  88. }
  89.